#include <cstdio>

const int N = 100005;
int n, l, r, a[N], L[N], R[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("range.in", "r", stdin);
  freopen("range.out", "w", stdout);
#endif
#endif

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= a[i] - a[i - 1]; ++j) {
      L[++l] = i;
    }
    for (int j = 1; j <= a[i - 1] - a[i]; ++j) {
      R[++r] = i - 1;
    }
  }
  for (int i = 1; i <= a[n]; ++i) R[++r] = n;
  printf("%d\n", l);
  for (int i = 1; i <= l; ++i) {
    printf("%d %d\n", L[i], R[i]);
  }
  return 0;
}